var app = angular.module('app',[]).controller('wdsc',
		function($scope,$http){
	
	
	
	$(function () {
	    $('.check input').iCheck({
	            checkboxClass: 'sty1-checkbox'
	        });
	});
	var getSessionUser = function(){ 
		   $http.post("../pub/getSessionUser").success(function(data){
			   $scope.username = data.username;
		   })
		} 
	getSessionUser();
	$scope.logout = function(){
    	$http.post("../pub/logout1").success(function(data) {
    		if(data.status == "ok"){
				window.open("../pub/userlogin");
			}
    	})
    }
	$scope.itemsPerPage = 2;
	$scope.currentPage = 1;
	$scope.totalItems = '';
	var getWdsc = function() {
		$scope.page = {"curPage":$scope.currentPage,
				"itemsPage":$scope.itemsPerPage
		};
		$http.post("./getWdsc",$scope.page).success(function(data){
			$scope.wdsc = [];
			$scope.totalItem = data.length
			
			for (var i=0,j=data.length;i<j;i++){
			    var sc = data[i];
			    $scope.wdsc.push(sc);
			    	
			    }
			
		})
	}
	getWdsc();
	var getAllWdsc = function() {
		
		$http.post("./getAllWdsc").success(function(data){
		
			$scope.totalItems = data[0].num;
			$scope.pageCount = ($scope.totalItems%$scope.itemsPerPage==0)?($scope.totalItems/$scope.itemsPerPage):parseInt($scope.totalItems/$scope.itemsPerPage+1);
		alert(data[0].num);
			
		})
	}
	
	getAllWdsc();
	
	
	$scope.p_index = function() {
		
			$scope.currentPage = 1;
			getWdsc();
		
	}
	

	$scope.p_prev = function() {
		if($scope.currentPage == 1){
			alert("已经是第一页了！");
			return;
		}if ($scope.currentPage > 1) {
			$scope.currentPage--;
			getWdsc();
			
		}
	}
	
	$scope.p_next = function() {
		if ($scope.currentPage>0 && $scope.currentPage<$scope.pageCount){
			$scope.currentPage++;
			getWdsc();
		}else if($scope.currentPage == $scope.pageCount){
			alert("已经是最后一页了！");
			return;
		}
	}
	
	$scope.p_last = function() {
			$scope.currentPage = $scope.pageCount;
			getWdsc();
	}
	
})